// plop-template/config.js
const { PREFIX } = require("./constants");
function promptsList() {
  return [
    {
      type: "input",
      name: "name",
      message: "组件名称",
      default: "myComponent",
    },
    {
      type: "input",
      name: "cnZhName",
      message: "组件中文名",
      default: "我的组件",
    },
    {
      type: "confirm",
      name: "combinationComponent",
      message: "是否是组合组件",
      default: false,
    },
  ];
}

function actionsList(type) {
  const componentAction = [
    {
      type: "add",
      path: "packages/components/{{name}}/index.ts", // 创建 组件 入口文件
      templateFile: "plop-template/component/index.hbs",
    },
    {
      type: "add",
      path: "packages/components/{{name}}/src/{{name}}.vue", // 创建vue模板
      templateFile: "plop-template/component/src/vue.hbs",
    },
    {
      type: "add",
      path: "packages/components/{{name}}/src/types.ts", // 创建props的ts模板(此文件也用作打包后的types提示)
      templateFile: "plop-template/component/src/ts.hbs",
    },
    {
      type: "modify",
      path: "packages/components/index.ts", // 添加记录到packages/components/index.ts文件中
      pattern: /(\/\/ -- append import --)/gi,
      template: "import Qi{{properCase name}} from './{{name}}'\r\n$1",
    },
    {
      type: "modify",
      path: "packages/components/index.ts", // 添加记录到packages/components/index.ts文件中
      pattern: /((\s{4})\/\/ -- append pushComponents --)/gi,
      template: "$2Qi{{properCase name}},\r\n$1",
    },
    {
      type: "modify",
      path: "packages/components/index.ts", // 添加记录到packages/components/index.ts文件中
      pattern: /(\/\/ -- append export --)/gi,
      template: "export * from './{{name}}'\r\n$1",
    },
    {
      type: "modify",
      path: "packages/types/index.ts", // 添加记录到packages/types/index.ts文件中
      pattern: /(\/\/ -- append import --)/gi,
      template:
        "import type { {{properCase name}}Component } from '@qi-ui-plus/components/{{name}}'\r\n$1",
    },
    {
      type: "modify",
      path: "packages/types/index.ts", // 添加记录到packages/types/index.ts文件中
      pattern: /((\s{4})\/\/ -- append export --)/gi,
      template: "$2Qi{{properCase name}}: {{properCase name}}Component\r\n$1",
    },
    // {
    //     type: 'add',
    //     path: 'packages/{{name}}/package.json',// 按需引入时添加
    //     templateFile: 'plop-template/component/package.hbs'
    // },
    // {
    //     type: 'add',
    //     path: 'packages/{{name}}/README.md',
    //     templateFile: 'plop-template/component/README.hbs'
    // },
    // {
    //   type: 'add',
    //   path: 'packages/{{name}}/__tests__/{{name}}.test.ts',
    //   templateFile: 'plop-template/component/__tests__/component.test.hbs'
    // },
    // {
    //   type: 'add',
    //   path: 'packages/{{name}}/stories/{{name}}.stories.ts',
    //   templateFile: 'plop-template/component/stories/component.stories.hbs'
    // },
    // {
    //   type: 'add',
    //   path: 'packages/{{name}}/LICENSE',
    //   templateFile: 'plop-template/component/LICENSE'
    // },
    // {
    //   type: 'add',
    //   path: 'packages/theme-chalk/src/{{name}}.scss',
    //   templateFile: 'plop-template/component/template.hbs'
    // }
  ];

  const docsAction = [
    {
      type: "add",
      path: "docs/components/{{name}}/index.md", // 创建md 文档docs模板
      templateFile: "plop-template/docs/md.hbs",
    },
    {
      type: "modify",
      path: "docs/.vitepress/config.js", // 添加路由记录 到docs/.vitepress/config.js文件中
      pattern: /((\s{16})\/\/ -- append sidebar --)/gi,
      template:
        "$2{ text: '{{cnZhName}}', link: '/components/{{name}}/'},\r\n$1",
    },
  ];

  return type == "component"
    ? componentAction
    : type == "docs"
    ? docsAction
    : componentAction.concat(docsAction);
}
module.exports = {
  promptsList,
  actionsList,
};
